import { headers } from 'next/headers';

export async function api(path: string) {
  // 服务端组件：根据当前 host 拼完整 URL
  if (typeof window === 'undefined') {
    const protocol = (await headers()).get('x-forwarded-proto') || 'http';
    const host = (await headers()).get('host');
    return `${protocol}://${host}${path}`;
  }
  // 浏览器：直接相对路径
  return path;
}